package com.sxpi.user.service.useramount;

import com.sxpi.common.result.R;
import com.sxpi.user.feign.api.UserServiceFeign;
import com.sxpi.user.vo.UserAmountVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * @Author: 董伟豪
 * @Date: 2022/11/8 21:30
 */
@Service
@Slf4j
public class UserAmountRecordServiceImpl implements IUserAmountRecordService{

    @Autowired
    private UserServiceFeign userServiceFeign;

    /**
     * 体现方法---无锁
     * @param userAmountVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R takeMoney(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoney(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - 悲观锁
     * @param userAmountVo
     * @return
     */
    @Override
    public R takeMoneyPessimismLock(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoneyPessimismLock(userAmountVo);
    }

    /**
     * 用户提现
     * 数据库-分布式锁解决方案 - 乐观锁
     * @param userAmountVo
     * @return
     */
    @Override
    public R takeMoneyOptimismLock(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoneyOptimismLock(userAmountVo);
    }

    @Override
    public R takeMoneyRedisLock(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoneyRedisLock(userAmountVo);
    }

    @Override
    public R takeMoneyZookeeperLock(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoneyZookeeperLock(userAmountVo);
    }

    @Override
    public R takeMoneyRedissonLock(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoneyRedissonLock(userAmountVo);
    }

    @Override
    public R takeMoneyRedissonTryLock(UserAmountVo userAmountVo) {
        return userServiceFeign.takeMoneyRedissonTryLock(userAmountVo);
    }
}
